using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;

using OrbitOne.Feed.Domain;
using OrbitOne.Feed.Interfaces;

using Spring.Context;
using Spring.Context.Support;

namespace OrbitOne.Feed.Handlers {
    /// <summary>
    /// The abstract base class for all writer classes.
    /// </summary>
    internal abstract class AbstractWriter {
        #region Members :
        protected XmlTextWriter _writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, null);
        protected WebFeed webFeed;
        #endregion Members 
        #region Ctor's :
        /// <summary>
        /// Initializes a new instance of the <see cref="T:AbstractWriter"/> class.
        /// </summary>
        public AbstractWriter(WebFeed webFeed) {
            this.webFeed = webFeed;
            _writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
        }
        #endregion Ctor's :
        #region Methods :
        /// <summary>
        /// Writes an element xml and initializes it with specified value.
        /// </summary>
        /// <param name="elementName">Name of the element.</param>
        /// <param name="value">The value.</param>
        public void WriteElementValue(String elementName, String value) {
            if (!String.IsNullOrEmpty(value)) {
                this._writer.WriteElementString(elementName, value);
            }
        }
        /// <summary>
        /// Writes an xml attribute in case provided value is not null or empty value.
        /// </summary>
        /// <param name="elementName">Name of the element.</param>
        /// <param name="value">The value.</param>
        public void WriteAttributeValue(String attributeName, String value) {
            if (!String.IsNullOrEmpty(value)) {
                this._writer.WriteAttributeString(attributeName, value);
            }
        }
        #region Implementation Abstract methods :
        /// <summary>
        /// Writes the actual feed in to the Http output stream.
        /// This method must be implemented by specific Writers like the Atom, RSS or podcast writers.
        /// </summary>
        /// <param name="webFeed">The web feed.</param>
        public abstract void WriteFeed();
        /// <summary>
        /// Writes a single topic info into the Http Output stream.
        /// </summary>
        /// <param name="topic">The topic.</param>
        protected abstract void WriteTopic(Topic topic);
        /// <summary>
        /// Write the feed author to the Http Output Stream
        /// </summary>
        protected abstract void WriteFeedAuthor();
        /// <summary>
        /// Writes some attributes to the root element e.g version of the feed format, namespaces, ...
        /// </summary>
        protected abstract void WriteRootAttributes();
        /// <summary>
        /// Writes the associated categories of a topic out to the Http Output stream.
        /// </summary>
        /// <param name="topic"></param>
        protected abstract void WriteTopicCategories(Topic topic);
        /// <summary>
        /// Writes the content of a topic to the Http Output stream
        /// </summary>
        /// <param name="topic"></param>
        protected abstract void WriteTopicContent(Topic topic);
        /// <summary>
        /// Writes the topic author info like name and email to the Http Output stream.
        /// </summary>
        /// <param name="topic"></param>
        protected abstract void WriteTopicAuthor(Topic topic);
        /// <summary>
        /// Writes an idenfitier for a topic, to allow the feed reader to differentiate between topics, 
        /// and flag topics as read.
        /// </summary>
        /// <param name="topic"></param>
        protected abstract void WriteTopicIdentification(Topic topic);
        /// <summary>
        /// Writes the publish date time or the last modified date of a topic.
        /// </summary>
        /// <param name="topic">The topic.</param>
        protected abstract void WriteTopicPublishDateTime(Topic topic);
        /// <summary>
        /// Writes the link of the web feed
        /// </summary>
        protected abstract void WriteFeedUrl();
        /// <summary>
        /// Writes the feed description to the Http Ouput stream.
        /// </summary>
        protected abstract void WriteFeedDescription();
        /// <summary>
        /// Writes the feed's title to the Http Ouput stream.
        /// </summary>
        protected abstract void WriteFeedTitle();
        /// <summary>
        /// Writes the last update date time of the feed
        /// </summary>
        protected abstract void WriteFeedLastUpdated(); 
        /// <summary>
        /// Writes the copyright text.
        /// </summary>
        protected abstract void WriteCopyright();
        /// <summary>
        /// Writes the root element
        /// </summary>
        protected abstract void WriteFeedRootElement();
        #endregion Implementation Abstract methods 
        #endregion Methods
    }

}
